package com.ibm.mall.action;

import java.io.ByteArrayInputStream;
import java.sql.SQLException;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ibm.mall.model.Commodity;
import com.ibm.mall.service.CommodityService;
import com.opensymphony.xwork2.ActionSupport;

@Controller
@Scope("prototype")
public class ShowImg extends ActionSupport {

	private static final long serialVersionUID = 1L;
	
	@Resource
	private CommodityService commodityService;
	
	private Integer commodityId;
	
	private ByteArrayInputStream inputStream;
	
	public String execute() {
		Commodity commodity=commodityService.getCommodityById(commodityId);
		try {
			inputStream=new ByteArrayInputStream(commodity.getCommodityImage().getBytes(1, (int) commodity.getCommodityImage().length()));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	public Integer getCommodityId() {
		return commodityId;
	}

	public void setCommodityId(Integer commodityId) {
		this.commodityId = commodityId;
	}

	public ByteArrayInputStream getInputStream() {
		return inputStream;
	}

	public void setInputStream(ByteArrayInputStream inputStream) {
		this.inputStream = inputStream;
	}

}
